﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using HumanManagement.BusinessObjects;

namespace HumanManagement.DataAccess
{
	public class ForeignLanguageSkillDA
	{

		#region ***** Init Methods ***** 
		public ForeignLanguageSkillDA()
		{
		}
		#endregion

		#region ***** Get Methods ***** 
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public ForeignLanguageSkill Populate(IDataReader myReader)
		{
			ForeignLanguageSkill obj = new ForeignLanguageSkill();
			obj.ID = (int) myReader["ID"];
			obj.PersonalProfileID = (int) myReader["PersonalProfileID"];
			obj.ForeignLanguageLevelID = (int) myReader["ForeignLanguageLevelID"];
			obj.ForeignLanguageID = (int) myReader["ForeignLanguageID"];
			obj.ProvidedBy = (string) myReader["ProvidedBy"];
			obj.IssuedOn = (DateTime) myReader["IssuedOn"];
			obj.LastDate = (DateTime) myReader["LastDate"];
			obj.LastMakerID = (int) myReader["LastMakerID"];
			obj.LastApproverID = (int) myReader["LastApproverID"];
            obj.ForeignLanguageSkillStatus = (string)myReader["ForeignLanguageSkillStatus"];
			return obj;
		}

		/// <summary>
		/// Get ForeignLanguageSkill by id
		/// </summary>
		/// <param name="id">ID</param>
		/// <returns>ForeignLanguageSkill</returns>
        public ForeignLanguageSkill GetByID(int id, int PersonalProfileID)
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ForeignLanguageSkill_GetByID", 
                                                                Data.CreateParameter("ID", id),
                                                                Data.CreateParameter("PersonalProfileID", PersonalProfileID)))
			{
				if (reader.Read())
				{
					return Populate(reader);
				}
				return null;
			}
		}

		/// <summary>
		/// Get all of ForeignLanguageSkill
		/// </summary>
		/// <returns>List<<ForeignLanguageSkill>></returns>
		public List<ForeignLanguageSkill> GetList()
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ForeignLanguageSkill_Get"))
			{
				List<ForeignLanguageSkill> list = new List<ForeignLanguageSkill>();
				while (reader.Read())
				{
				list.Add(Populate(reader));
				}
				return list;
			}
		}

		/// <summary>
		/// Get DataSet of ForeignLanguageSkill
		/// </summary>
		/// <returns>DataSet</returns>
        public DataSet GetDataSet(int PersonalProfileID)
		{
            return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ForeignLanguageSkill_Get"
                                            , Data.CreateParameter("PersonalProfileID", PersonalProfileID));
		}


		/// <summary>
		/// Get all of ForeignLanguageSkill paged
		/// </summary>
		/// <param name="recperpage">record per page</param>
		/// <param name="pageindex">page index</param>
		/// <returns>List<<ForeignLanguageSkill>></returns>
		public List<ForeignLanguageSkill> GetListPaged(int recperpage, int pageindex)
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ForeignLanguageSkill_GetPaged"
							,Data.CreateParameter("recperpage", recperpage)
							,Data.CreateParameter("pageindex", pageindex)))
			{
				List<ForeignLanguageSkill> list = new List<ForeignLanguageSkill>();
				while (reader.Read())
				{
				list.Add(Populate(reader));
				}
				return list;
			}
		}

		/// <summary>
		/// Get DataSet of ForeignLanguageSkill paged
		/// </summary>
		/// <param name="recperpage">record per page</param>
		/// <param name="pageindex">page index</param>
		/// <returns>DataSet</returns>
		public DataSet GetDataSetPaged(int recperpage, int pageindex)
		{
			return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ForeignLanguageSkill_GetPaged"
							,Data.CreateParameter("recperpage", recperpage)
							,Data.CreateParameter("pageindex", pageindex));
		}





		#endregion

		#region ***** Add Update Delete Methods ***** 
		/// <summary>
		/// Add a new ForeignLanguageSkill within ForeignLanguageSkill database table
		/// </summary>
		/// <param name="obj">ForeignLanguageSkill</param>
		/// <returns>key of table</returns>
		public int Add(ForeignLanguageSkill obj)
		{
			DbParameter parameterItemID = Data.CreateParameter("ID", obj.ID);
			parameterItemID.Direction = ParameterDirection.Output;
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ForeignLanguageSkill_Add"
							,parameterItemID
							,Data.CreateParameter("PersonalProfileID", obj.PersonalProfileID)
							,Data.CreateParameter("ForeignLanguageLevelID", obj.ForeignLanguageLevelID)
							,Data.CreateParameter("ForeignLanguageID", obj.ForeignLanguageID)
							,Data.CreateParameter("ProvidedBy", obj.ProvidedBy)
							,Data.CreateParameter("IssuedOn", obj.IssuedOn)
							,Data.CreateParameter("LastDate", obj.LastDate)
							,Data.CreateParameter("LastMakerID", obj.LastMakerID)
							,Data.CreateParameter("LastApproverID", obj.LastApproverID)
                            , Data.CreateParameter("ForeignLanguageSkillStatus", obj.ForeignLanguageSkillStatus)
			);
			return (int)parameterItemID.Value;
		}

		/// <summary>
		/// updates the specified ForeignLanguageSkill
		/// </summary>
		/// <param name="obj">ForeignLanguageSkill</param>
		/// <returns></returns>
		public void Update(ForeignLanguageSkill obj)
		{
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ForeignLanguageSkill_Update"
							,Data.CreateParameter("ID", obj.ID)
							,Data.CreateParameter("PersonalProfileID", obj.PersonalProfileID)
							,Data.CreateParameter("ForeignLanguageLevelID", obj.ForeignLanguageLevelID)
							,Data.CreateParameter("ForeignLanguageID", obj.ForeignLanguageID)
							,Data.CreateParameter("ProvidedBy", obj.ProvidedBy)
							,Data.CreateParameter("IssuedOn", obj.IssuedOn)
							,Data.CreateParameter("LastDate", obj.LastDate)
							,Data.CreateParameter("LastMakerID", obj.LastMakerID)
							,Data.CreateParameter("LastApproverID", obj.LastApproverID)
                            , Data.CreateParameter("ForeignLanguageSkillStatus", obj.ForeignLanguageSkillStatus)
			);
		}

		/// <summary>
		/// Delete the specified ForeignLanguageSkill
		/// </summary>
		/// <param name="id">ID</param>
		/// <returns></returns>
		public void Delete(int id)
		{
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ForeignLanguageSkill_Delete", Data.CreateParameter("ID", id));
		}
		#endregion
	}
}
